DROP TABLE IF EXISTS `nuke_medialibrary`;
CREATE TABLE IF NOT EXISTS `nuke_medialibrary` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `type` enum('image','video','audio','mp4','mov','avi','wmv','webm','mkv','txt','pdf','doc','docx','xls','xlsx','ppt','pptx','') NOT NULL,
  `url` varchar(255) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `catgallery_id` int(11) DEFAULT NULL,
  `subcatgallery_id` int(11) DEFAULT NULL,
  `file_size` int(11) DEFAULT NULL,
  `width` int(11) DEFAULT NULL,
  `height` int(11) DEFAULT NULL,
  `thumbnail_url` varchar(255) DEFAULT NULL,
  `is_external` tinyint(1) NOT NULL DEFAULT 0,
  `external_source` varchar(50) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  `view_count` int(11) NOT NULL DEFAULT 0,
  `upload_date` datetime DEFAULT current_timestamp() COMMENT 'Fecha de subida del archivo',
  `original_url` varchar(255) DEFAULT NULL COMMENT 'URL original si es contenido externo',
  `description` text DEFAULT NULL COMMENT 'Descripción del archivo',
  PRIMARY KEY (`id`),
  KEY `category_id` (`catgallery_id`),
  KEY `subcategory_id` (`subcatgallery_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

INSERT INTO `nuke_medialibrary` (`id`, `title`, `type`, `url`, `created_at`, `catgallery_id`, `subcatgallery_id`, `file_size`, `width`, `height`, `thumbnail_url`, `is_external`, `external_source`, `created_by`, `updated_at`, `updated_by`, `view_count`, `upload_date`, `original_url`, `description`) VALUES
(1, 'Desafio mental', 'image', 'uploads/multimedios/otros/desafio_mental.jpg', '2024-09-26 10:23:48', 7, NULL, NULL, NULL, NULL, NULL, 0, NULL, 2, '2025-05-20 18:07:17', 0, 10, '2025-05-20 06:28:23', NULL, ''),
(2, 'Bandera en el cielo', 'image', 'uploads/multimedios/otros/paiseje_colombia.jpg', '2024-09-25 08:47:38', 7, NULL, NULL, NULL, NULL, NULL, 0, NULL, 2, '2025-05-20 18:07:08', 0, 1, '2025-05-20 06:28:23', NULL, '');

DROP TABLE IF EXISTS `nuke_medialibrary_categories`;
CREATE TABLE IF NOT EXISTS `nuke_medialibrary_categories` (
  `catgallery_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `description` text DEFAULT NULL,
  `folder_name` varchar(255) NOT NULL,
  `created_at` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `updated_at` datetime DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  PRIMARY KEY (`catgallery_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
INSERT INTO `nuke_medialibrary_categories` (`catgallery_id`, `name`, `description`, `folder_name`, `created_at`, `created_by`)
VALUES
(1, 'Institucional', 'Información sobre la empresa y su equipo', 'institucional', NOW(), 1),
(2, 'Productos', 'Detalles de los productos ofrecidos por NESA Industrial S.A.S.', 'productos', NOW(), 1),
(3, 'Aplicaciones', 'Áreas de aplicación de los productos', 'aplicaciones', NOW(), 1),
(4, 'Documentación Técnica', 'Documentos técnicos y estudios relacionados', 'documentacion_tecnica', NOW(), 1),
(5, 'Noticias y Eventos', 'Actualizaciones y eventos recientes', 'noticias_eventos', NOW(), 1);



DROP TABLE IF EXISTS `nuke_medialibrary_exif`;
CREATE TABLE IF NOT EXISTS `nuke_medialibrary_exif` (
  `exif_id` int(11) NOT NULL AUTO_INCREMENT,
  `media_id` int(11) NOT NULL,
  `camera_make` varchar(100) DEFAULT NULL,
  `camera_model` varchar(100) DEFAULT NULL,
  `date_taken` datetime DEFAULT NULL,
  `exposure` varchar(50) DEFAULT NULL,
  `aperture` varchar(50) DEFAULT NULL,
  `iso` varchar(50) DEFAULT NULL,
  `focal_length` varchar(50) DEFAULT NULL,
  `flash` varchar(50) DEFAULT NULL,
  `gps_latitude` varchar(50) DEFAULT NULL,
  `gps_longitude` varchar(50) DEFAULT NULL,
  `raw_exif` text DEFAULT NULL,
  PRIMARY KEY (`exif_id`),
  KEY `media_id` (`media_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

DROP TABLE IF EXISTS `nuke_medialibrary_logs`;
CREATE TABLE IF NOT EXISTS `nuke_medialibrary_logs` (
  `log_id` int(11) NOT NULL AUTO_INCREMENT,
  `media_id` int(11) DEFAULT NULL,
  `catgallery_id` int(11) DEFAULT NULL,
  `subcatgallery_id` int(11) DEFAULT NULL,
  `user_id` int(11) NOT NULL,
  `user_ip` varchar(45) NOT NULL,
  `action` varchar(50) NOT NULL,
  `action_details` text DEFAULT NULL,
  `action_date` datetime NOT NULL,
  PRIMARY KEY (`log_id`),
  KEY `media_id` (`media_id`),
  KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

DROP TABLE IF EXISTS `nuke_medialibrary_reactions`;
CREATE TABLE IF NOT EXISTS `nuke_medialibrary_reactions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `media_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `reaction_type` varchar(20) NOT NULL,
  `reaction_date` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `media_user_unique` (`media_id`,`user_id`,`reaction_type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

INSERT INTO `nuke_medialibrary_reactions` (`id`, `media_id`, `user_id`, `reaction_type`, `reaction_date`) VALUES
(5, 1, 2, 'me_gusta', '2025-04-02 14:24:40'),
(3, 3, 2, 'me_gusta', '2025-04-02 14:24:15'),
(4, 20, 2, 'me_gusta', '2025-04-02 14:24:34'),
(6, 1, 2, 'me_rie', '2025-04-02 14:26:04');

DROP TABLE IF EXISTS `nuke_medialibrary_subcategories`;
CREATE TABLE IF NOT EXISTS `nuke_medialibrary_subcategories` (
  `subcatgallery_id` int(11) NOT NULL AUTO_INCREMENT,
  `catgallery_id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `description` text DEFAULT NULL,
  `folder_name` varchar(255) NOT NULL,
  `created_at` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `updated_at` datetime DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  PRIMARY KEY (`subcatgallery_id`),
  KEY `category_id` (`catgallery_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

INSERT INTO `nuke_medialibrary_subcategories` (`subcatgallery_id`, `catgallery_id`, `name`, `description`, `folder_name`, `created_at`, `created_by`)
VALUES
-- Subcategorías para Institucional
(1, 1, 'Misión y Visión', 'Información sobre la misión y visión de la empresa', 'mision_vision', NOW(), 1),
(2, 1, 'Nuestro Equipo', 'Presentación del equipo de trabajo', 'nuestro_equipo', NOW(), 1),

-- Subcategorías para Productos
(3, 2, 'AirPlus', 'Detalles del producto AirPlus', 'airplus', NOW(), 1),
(4, 2, 'AirUltra', 'Detalles del producto AirUltra', 'airultra', NOW(), 1),
(5, 2, 'AirMax', 'Detalles del producto AirMax', 'airmax', NOW(), 1),

-- Subcategorías para Aplicaciones
(6, 3, 'Áreas Estériles', 'Aplicaciones en áreas estériles', 'areas_esteriles', NOW(), 1),
(7, 3, 'Procesamiento de Alimentos', 'Aplicaciones en la industria alimentaria', 'procesamiento_alimentos', NOW(), 1),
(8, 3, 'Invernaderos', 'Aplicaciones en invernaderos', 'invernaderos', NOW(), 1),
(9, 3, 'Transporte Refrigerado', 'Aplicaciones en transporte refrigerado', 'transporte_refrigerado', NOW(), 1),

-- Subcategorías para Documentación Técnica
(10, 4, 'Fichas Técnicas', 'Fichas técnicas de productos', 'fichas_tecnicas', NOW(), 1),
(11, 4, 'Manuales de Usuario', 'Manuales de uso de productos', 'manuales_usuario', NOW(), 1),
(12, 4, 'Estudios de Caso', 'Casos de estudio relacionados', 'estudios_caso', NOW(), 1),

-- Subcategorías para Noticias y Eventos
(13, 5, 'Noticias Corporativas', 'Noticias relacionadas con la empresa', 'noticias_corporativas', NOW(), 1),
(14, 5, 'Participación en Ferias', 'Eventos y ferias en los que participa la empresa', 'participacion_ferias', NOW(), 1),
(15, 5, 'Publicaciones Recientes', 'Últimas publicaciones y artículos', 'publicaciones_recientes', NOW(), 1);
